package com.jz.netthings.analysis.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jz.netthings.analysis.bean.operManage.CollMacRuningStatus;
import com.jz.netthings.analysis.bean.operManage.NewProviderDisplay;
import com.jz.netthings.analysis.bean.operManage.ProviderProcess;
import com.jz.netthings.analysis.bean.operManage.QueryCollMacRuningStatusSupport;
import com.jz.netthings.analysis.service.CollMacRuningStatusService;
import com.jz.netthings.analysis.service.NewProviderDisplayService;
import com.jz.netthings.analysis.service.ProviderProcessService;
import com.jz.netthings.appengine.baseData.ProviderInfo;
import com.jz.netthings.bean.system.JyUser;
import com.jz.netthings.exception.AdscmSystemException;
import com.jz.netthings.support.SimpleCoreResponse;
import com.jz.netthings.system.service.JyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.*;

/**
 * <p>
 *  营运管理前端控制器
 * </p>
 *
 * @author yangyunyun
 * @since 2019-07-10
 */
@RestController
@RequestMapping("/adscm/analysis/operationalManagement")
public class OperationalManagementController {

    @Autowired
    NewProviderDisplayService newProviderDisplayService;

    @Autowired
    ProviderProcessService providerProcessService;

    @Autowired
    CollMacRuningStatusService collMacRuningStatusService;

    @Autowired
    JyUserService jyUserService;

    /**
     * 构造某一年的新浆员献浆过程时序图
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadNewProviderDisplay")
    public SimpleCoreResponse loadNewProviderDisplay(int year) throws AdscmSystemException {

        newProviderDisplayService.loadNewProviderDisplay(year);

        return new SimpleCoreResponse("200", "执行成功", null);
    }

    /**
     * 构造某个新浆员献浆过程时序图
     * @param info
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadOneNewProviderDisplay")
    public SimpleCoreResponse loadOneNewProviderDisplay(ProviderInfo info) throws AdscmSystemException {
        return new SimpleCoreResponse("200", "执行成功", newProviderDisplayService.loadNewProviderDisplay(info));
    }


    /**
     * 根据日期构造献浆过程折线图
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadProviderProcessByTime")
    public SimpleCoreResponse loadProviderProcessByTime(String date) throws AdscmSystemException {


        return new SimpleCoreResponse("200", "执行成功", providerProcessService.loadProviderProcessByTime(date));
    }
    /**
     * 根据日期构造某一天的单采机运行状况综合统计数据
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/loadCollMacRunningStatus")
    public SimpleCoreResponse loadCollMacRunningStatus(String date) throws AdscmSystemException {

        collMacRuningStatusService.loadCollMacRunningStatus(date);
        return new SimpleCoreResponse("200", "执行成功", null);
    }

    //上面是构造数据
    ////////////////////////////////////////////////////////////////////////////////////////////
    //下面是查询数据

    /**
     * 新浆员献浆过程时序图
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/newProviderDisplay")
    public SimpleCoreResponse newProviderDisplay(String date) throws AdscmSystemException {

        Wrapper<NewProviderDisplay> wrapper = new EntityWrapper<>();
        wrapper.eq("createDate",date);

        return new SimpleCoreResponse("200", "查询成功", newProviderDisplayService.selectList(wrapper));
    }
    /**
     * 浆员献浆过程各环节数量统计图
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/providerHjCount")
    public SimpleCoreResponse providerHjCount(String date) throws AdscmSystemException {

        Wrapper<ProviderProcess> wrapper = new EntityWrapper<>();
        wrapper.eq("date",date);

        return new SimpleCoreResponse("200", "查询成功", providerProcessService.selectList(wrapper));
    }
    /**
     * 当天进站浆员的献浆频次饼图
     *
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/pulpingFrequency")
    public SimpleCoreResponse pulpingFrequency(String date,Integer firstBlood,Integer secondBlood,Integer thirdBlood,Integer fourthBlood) throws AdscmSystemException {

        return new SimpleCoreResponse("200", "查询成功", providerProcessService.pulpingFrequency(date,firstBlood,secondBlood,thirdBlood,fourthBlood));
    }

    /**
     * 根据日期查询这一天的单采机运行状况综合统计数据
     * @param
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getCollMacRunningStatus")
    public SimpleCoreResponse getCollMacRunningStatus(QueryCollMacRuningStatusSupport queryCmrsSupport) throws AdscmSystemException {
//        if (nurseIds != null && nurseIds.length>0){
//            queryCmrsSupport.setNurseIdList(Arrays.asList(nurseIds));
//        }
        return new SimpleCoreResponse("200", "查询成功", collMacRuningStatusService.selectCollMacRunningStatus(queryCmrsSupport));
    }

    /**
     * 查询所有护士
     * @param isCollNurse 是否只查询采浆护士
     * @return
     * @throws AdscmSystemException
     */
    @RequestMapping("/getAllNurse")
    public SimpleCoreResponse getAllNurse(Boolean isCollNurse) throws AdscmSystemException {

        List<JyUser> jyUsers = null;
        if (isCollNurse != null && isCollNurse){
//            jyUsers = jyUserService.queryUsersByRoleId("38");
            jyUsers = jyUserService.queryUsersByRoleCode("ROLE_coll_user_nurse");
        }else{
            Wrapper<JyUser> wrapper = new EntityWrapper<>();
            wrapper.eq("unit_id",2);
            jyUsers = jyUserService.selectList(wrapper);
        }

        return new SimpleCoreResponse("200", "查询成功", jyUsers);
    }
}
